// pages/shopping-mall/shopping-mall.js
var app = getApp();
var util = require('../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    util: util,
    tc: 0,

    orgInfo: '',
    screen_w: 320,
    screen_h: 480,
    
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    var tc = app.get_tc();
    
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        var isIphone_x = (res.model.indexOf('iPhone X') >= 0);
        var contentWidth = res.windowWidth - 60;
        that.setData({
          isIphone_x: isIphone_x,
          screen_w: res.windowWidth,
          screen_h: res.windowHeight,
          mainScrollview_h: isIphone_x ? res.windowWidth - 20 : res.windowWidth
        });


      }
    })

    app.GetUserInfo(util.orgid, function (res) {
      console.log("小程序信息：", res);
      that.setData({
        orgInfo: res
      })
      wx.setNavigationBarTitle({
        title: res.uname,
      })
    });

    this.loadGHS();
  },

  // 读取供货商
  loadGHS: function () {
    var that = this;
    var params = {
      publickey: util.publiccode,
      ac: "getghs",
      orgid: util.orgid,
      page: 1,
      num: 100
    }
    util.api({
      data: params,
      success: function (responseData) {
        var result = responseData.data;
        console.log("供货商数据：", result);
        if (!result.msg) {
            that.setData({
              ghsData: result
            });
        } else {
            that.setData({
              ghsData: []
            })
        }
        wx.hideLoading();
      }
    });
  },

  selectMendian:function(e){
    let mendianId = e.currentTarget.dataset.selghs;
    wx.setStorageSync('mendianid', mendianId);
    var pages=getCurrentPages();//页面指针数组
    var prepage=pages[pages.length-2];//上一页面指针
    prepage.regetMendianID(mendianId);
    this.gobackPage();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
    //获取颜色配置
    app.getColorSetData(function (color) {
      that.setData({
        colorSet: color
      })
      that.resetNavColor();
    });
  },
  //设置titlebar 样式
  resetNavColor: function () {
    var bg_color = '#f0f0f0';
    var fg_color = '#000000';
    if (this.data.colorSet) {
      bg_color = this.data.colorSet.titlebg;
      fg_color = this.data.colorSet.titlefont;
    }
    wx.setNavigationBarColor({
      frontColor: fg_color,
      backgroundColor: bg_color
    })
  },


  gobackPage:function(){
    wx.navigateBack({
      delta: 1,
    })
  }

})